# coding: utf-8

from leancloud import Engine
from leancloud import LeanEngineError
from app import app

import sys
import json
sys.path.append('./cloud')
sys.path.append('./games')
import games
import gomoku

engine = Engine(app)

@engine.define
def getGamesList(userID):
    return games.getList(userID)

@engine.define
def addFavorite(gameID, userID):
    return games.addFavorite(gameID, userID)

@engine.define
def rmFavorite(gameID, userID):
    return games.rmFavorite(gameID,userID)

@engine.define
def clickGame(gameID):
    return games.click(gameID)

@engine.define
def _messageReceived(**params):
    content = json.loads(params['content'])
    print("in _messageReceived")
    print(content)
    if "_lctype" in content and "_lcattrs" in content:
        if content['_lctype'] == 1:
            gomoku.analysis_game_data(content['_lcattrs'])
            print("web1")
    print(content)
    return {
        'content': content,
    }

@engine.define
def test_gomoku(**params):
    print("para:",params)
    content = params['content']
    if "_lctype" in content and "_lcattrs" in content:
        if content['_lctype'] == 1:
            gomoku.analysis_game_data(content['_lcattrs'])
    return {
        'content': content,
    }

if __name__ == '__main__':
    # 只在本地开发环境执行的代码
    print('function test')
